package design;

import lombok.AllArgsConstructor;
import lombok.Data;

class ChatRoom{
    public void showMsg(User user,String msg){
        System.out.println("["+user.getName()+"]"+msg);
    }
}

@Data
@AllArgsConstructor
class User{
    private String name;
    private ChatRoom chatRoom;

    public void sendMessage(String msg){
        this.chatRoom.showMsg(this,msg);
    }
}

public class Client {
    public static void main(String[] args) {
        ChatRoom room = new ChatRoom();

        User tom = new User("Tom",room);
        User jerry = new User("Jerry",room);
        tom.sendMessage("AAAAAAAAAAA");
        jerry.sendMessage("BBBBBBBBBBBBBBB");
    }

}
